home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z8.ADF / Nart / nart.c < prev    next >
C/C++ Source or Header  |  1986-07-05  |  5KB  |  180 lines

  1. /*  :ts=8 bk=0                                              From: AMIGA.3955
  2.  * NART.C
  3.  * In the tradition of stupid programs, Leo Schwab presents (yet again)
  4.  * The Art Program.
  5.  *
  6.  * Modified to do even neater things.
  7.  * 8607.1
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <graphics/gfxbase.h>
  12. #include <intuition/intuition.h>
  13.  
  14. #define XSIZE           319
  15. #define YSIZE           199
  16.  
  17. extern int rnd();
  18.  
  19. struct IntuitionBase    *IntuitionBase;
  20. struct GfxBase          *GfxBase;
  21. struct Screen   *scr, *OpenScreen();
  22. struct Window   *win, *OpenWindow();
  23. struct ViewPort *vp;
  24.  
  25. struct NewScreen scrdef = {
  26.         0, 0, XSIZE+1, YSIZE+1,
  27.         4,              /*  16 colors  */
  28.         0, 1,           /*  detail/block pens  */
  29.                         /*  "Automatically" set up screen format  */
  30.         ((XSIZE>320) ? HIRES : 0) | ((YSIZE>200) ? LACE : 0),
  31.         CUSTOMSCREEN,
  32.         NULL, NULL, NULL, NULL  /* no special font, title, gadg, or bitmap */
  33. };
  34.  
  35. struct NewWindow windef = {
  36.         0, 0, XSIZE+1, YSIZE+1,
  37.         0, 1,
  38.         CLOSEWINDOW,
  39.         WINDOWCLOSE | BACKDROP | BORDERLESS,
  40.         NULL, NULL, NULL,       /* no special gadget, checkmark or title */
  41.         NULL,                   /* screen pointer; will get set later */
  42.         NULL,                   /* no custom bitmap */
  43.         0, 0, 0, 0,             /* ignored */
  44.         CUSTOMSCREEN
  45. };
  46.  
  47. main ()
  48. {
  49.         register struct RastPort *rp;
  50.         int i, dx1, dy1, dx2, dy2, pen = 16, flag = 0,
  51.             xa1[150], ya1[150], xa2[150], ya2[150];
  52.         register int x1, y1, x2, y2;
  53.  
  54.         openstuff ();
  55.         rnd (-87634);
  56. /*      rp = win -> RPort;    <-- This is slower because of layers    */
  57.         rp = & (scr -> RastPort);
  58.         SetDrMd (rp, COMPLEMENT);
  59.         ShowTitle (scr, FALSE);
  60.         SetRast (rp, 0);
  61.         x1 = rnd (XSIZE+1);  y1 = rnd (YSIZE+1);
  62.         x2 = rnd (XSIZE+1);  y2 = rnd (YSIZE+1);
  63.         setdisp (&dx1, &dy1);
  64.         setdisp (&dx2, &dy2);
  65.  
  66.        while (1) {
  67.         for (i=0; i<150; i++) {
  68.                 rotate ();
  69.                 if (GetMsg (win -> UserPort)) {
  70.                         closestuff ();
  71.                         exit (TRUE);
  72.                 }
  73.                 if (rnd (12) == 3)
  74.                         if (rnd (2))
  75.                                 setdisp (&dx1, &dy1);
  76.                         else
  77.                                 setdisp (&dx2, &dy2);
  78.  
  79.                 x1 += dx1;  y1 += dy1;
  80.                 if (x1 > XSIZE || x1 < 0) {
  81.                         dx1 = -dx1;
  82.                         x1 = x1<0 ? 0 : XSIZE;
  83.                 }
  84.                 if (y1 > YSIZE || y1 < 0) {
  85.                         dy1 = -dy1;
  86.                         y1 = y1<0 ? 0 : YSIZE;
  87.                 }
  88.                 x2 += dx2;  y2 += dy2;
  89.                 if (x2 > XSIZE || x2 < 0) {
  90.                         dx2 = -dx2;
  91.                         x2 = x2<0 ? 0 : XSIZE;
  92.                 }
  93.                 if (y2 > YSIZE || y2 < 0) {
  94.                         dy2 = -dy2;
  95.                         y2 = y2<0 ? 0 : YSIZE;
  96.                 }
  97.  
  98.                 if (!--pen)
  99.                         pen = 15;
  100.                 rp -> Mask = pen;       /* kludge; COMPLEMENT does not  */
  101.                 Move (rp, x1, y1);      /* perform as advertised  */
  102.                 Draw (rp, x2, y2);
  103.                 if (flag) {
  104.                         Move (rp, xa1[i], ya1[i]);
  105.                         Draw (rp, xa2[i], ya2[i]);
  106.                 }
  107.                 xa1[i] = x1;  ya1[i] = y1;
  108.                 xa2[i] = x2;  ya2[i] = y2;
  109.         }
  110.        flag = 1;
  111.        }        /* End of the while */
  112. }
  113.  
  114. openstuff ()
  115. {
  116.         if (!(IntuitionBase = (struct IntuitionBase *)
  117.             OpenLibrary ("intuition.library", 1))) {
  118.                 printf ("Awright, where's Intuition?\n");
  119.                 exit (FALSE);
  120.         }
  121.  
  122.         if (!(GfxBase = (struct GfxBase *)
  123.             OpenLibrary ("graphics.library", 1))) {
  124.                 printf ("Graphics?  Heeeere graphics....\n");
  125.                 exit (FALSE);
  126.         }
  127.  
  128.         if (!(scr = OpenScreen (&scrdef))) {
  129.                 printf ("Can't open your screen.\n");
  130.                 exit (FALSE);
  131.         }
  132.  
  133.         windef.Screen = scr;
  134.         if (!(win = OpenWindow (&windef))) {
  135.                 printf ("Window painted shut.\n");
  136.                 exit (FALSE);
  137.         }
  138.         vp = &(scr -> ViewPort);
  139.         setcolors ();
  140. }
  141.  
  142. closestuff ()
  143. {
  144.         CloseWindow (win);
  145.         CloseScreen (scr);
  146.         CloseLibrary (GfxBase);
  147.         CloseLibrary (IntuitionBase);
  148. }
  149.  
  150. setdisp (x, y)
  151. register int *x, *y;
  152. {
  153.         *x = rnd (9) - 4;
  154.         *y = rnd (9) - 4;
  155. }
  156.  
  157. /*  What I really wanted was the HSL color wheel.  Oh well....  */
  158. setcolors ()
  159. {
  160.         int r, g, b, i;
  161.  
  162.         for (i=1; i<16; i++) {
  163.                 if (i <= 5) {
  164.                         r = (6-i) * 15 / 5;
  165.                         g = (i-1) * 15 / 5;
  166.                         b = 0;
  167.                 } else if (i > 5 && i <= 10) {
  168.                         r = 0;
  169.                         g = (11-i) * 15 / 5;
  170.                         b = (i-5) * 15 / 5;
  171.                 } else if (i > 10) {
  172.                         r = (i-10) * 15 / 5;
  173.                         g = 0;
  174.                         b = (16-i) * 15 / 5;
  175.                 }
  176.                 SetRGB4 (vp, i, r, g, b);
  177.         }
  178.         SetRGB4 (vp, 0, 0, 0, 0);
  179. }
  180.